﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace SwaggerDemo.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class WeatherForecastController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };

        private readonly ILogger<WeatherForecastController> _logger;

        public WeatherForecastController(ILogger<WeatherForecastController> logger)
        {
            _logger = logger;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IEnumerable<WeatherForecast> Get()
        {
            var rng = new Random();
            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = rng.Next(-20, 55),
                Summary = Summaries[rng.Next(Summaries.Length)]
            })
            .ToArray();
        }

        /// <summary>
        /// Swagger Demo -> User
        /// </summary>
        /// <remarks>
        /// <para/>Author   :  An
        /// <para/>Date     :  2020-02-01
        /// </remarks>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("demo")]
        public string Demo()
        {
            return "User-> Demo Get";
        }

        /// <summary>
        /// Swagger Demo -> User
        /// </summary>
        /// <remarks>
        /// <para/>Author   :  An
        /// <para/>Date     :  2020-02-01
        /// </remarks>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("demo")]
        public string Demo(UserDto dto)
        {
            return "User-> Demo Post";
        }
    }

    /// <summary>
    /// User Info
    /// </summary>
    public class UserDto
    {
        /// <summary>
        /// 登录账号
        /// </summary>
        [Display(Name = "登录账号")]
        [Required(ErrorMessage = " {0} " + " is Required")]
        [MaxLength(255, ErrorMessage = " {0} " + "Max Length" + " 255")]
        public string Login_Name { get; set; }


        /// <summary>
        /// 密码Salt
        /// </summary>
        [Display(Name = "密码Salt")]
        [Required(ErrorMessage = " {0} " + " is Required")]
        [MaxLength(36, ErrorMessage = " {0} " + "Max Length" + " 255")]
        public string Password_Salt { get; set; }
    }
}
